package com.example.threadlocaldemo0.utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;

public class JdbcUtils {

    public static void quietlyRollback(Connection conn) {
        if (conn == null)
            return;
        try {
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void quietlyClose(Connection conn) {
        try {
            if (conn == null || conn.isClosed())
                return;
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void quietlyClose(PreparedStatement pst) {
        try {
            if (pst == null || pst.isClosed())
                return;
            pst.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}